using System;
using System.Collections;
using UnityEngine;
using Voodoo.Sauce.Internal.CrossPromo.Models;

namespace Voodoo.Sauce.Internal.CrossPromo.Canvas
{
	internal abstract class AFormatManager : MonoBehaviour
	{
		public static AFormatManager Instance;

		protected AssetModel Asset;

		protected bool IsActive;

		protected bool IsWaiting;

		private const string ItunesUrl = "https://itunes.apple.com/fr/app/apple-store/id{0}";

		private const string PlaystoreUrl = "https://play.google.com/store/apps/details?id={0}";

		public virtual void OnClickEvent()
		{
			if (Asset != null && Asset.game != null)
			{
				if (!string.IsNullOrEmpty(Asset.tracking_link))
				{
					new WWW(Asset.tracking_link);
				}
				Application.OpenURL($"https://play.google.com/store/apps/details?id={Asset.game.bundle_id}");
				VoodooCrossPromo.Callback.ClickEvent(Asset);
			}
		}

		public abstract void Display();

		public abstract void Hide();

		protected IEnumerator WaitCrossPromoReady(VideoManager videoManager)
		{
			while (!VoodooCrossPromo.Info.CrossPromoIsReady)
			{
				yield return null;
			}
			if (VoodooCrossPromo.Info.GetInternetStatus() || !IsActive)
			{
				if (IsActive)
				{
					VoodooCrossPromo.Callback.ErrorEvent(null);
				}
			}
			else
			{
				try
				{
					Asset = videoManager.ChooseVideo();
					if (Asset == null)
					{
						VoodooCrossPromo.Callback.ErrorEvent(null);
					}
				}
				catch (Exception message)
				{
					VoodooCrossPromo.Callback.ErrorEvent(message);
				}
			}
		}
	}
}
